//
//  PersonalTableViewCell.m
//  gamebox_qpp
//
//  Created by 赵隆杰 on 2022/9/1.
//

#import "PersonalTableViewCell.h"

@interface PersonalTableViewCell ()

@property (nonatomic, strong) UILabel *mainLabel;

@property (nonatomic, strong) UIView *arrowView;
@property (nonatomic, strong) UIView *fieldView;
@property (nonatomic, strong) UIView *headerView;

@end

@implementation PersonalTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        UILabel *mainLabel = [[UILabel alloc] init];
        mainLabel.textColor = kColor333333;
        mainLabel.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:mainLabel];
        [mainLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(14);
            make.centerY.equalTo(self.contentView);
        }];
        self.mainLabel = mainLabel;
        
        UILabel *lineLabel = [[UILabel alloc] init];
        lineLabel.backgroundColor = kLineColor;
        [self.contentView addSubview:lineLabel];
        [lineLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(14);
            make.bottom.right.equalTo(self.contentView);
            make.height.mas_equalTo(1);
        }];
        
        //arrow
        UIView *arrowView = [[UIView alloc] init];
        arrowView.hidden = YES;
        [self.contentView addSubview:arrowView];
        [arrowView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(100);
            make.bottom.mas_equalTo(-1);
            make.top.right.mas_equalTo(0);
        }];
        UIImageView *arrowImage = [[UIImageView alloc] init];
        arrowImage.image = [UIImage imageNamed_myself:@"my_self_back_black"];
        [arrowView addSubview:arrowImage];
        [arrowImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(5);
            make.height.mas_equalTo(10);
            make.centerY.equalTo(self.contentView);
            make.right.equalTo(arrowView).offset(-14);
        }];
        UILabel *arrowLabel = [[UILabel alloc] init];
        arrowLabel.textColor = kColor666666;
        arrowLabel.textAlignment = NSTextAlignmentRight;
        arrowLabel.font = [UIFont systemFontOfSize:14];
        [arrowView addSubview:arrowLabel];
        [arrowLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(arrowImage);
            make.right.equalTo(arrowImage.mas_left).offset(-10);
            make.left.equalTo(arrowView);
        }];
        self.arrowView = arrowView;
        
        //field
        UIView *fieldView = [[UIView alloc] init];
        fieldView.hidden = YES;
        [self.contentView addSubview:fieldView];
        [fieldView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(100);
            make.bottom.mas_equalTo(-1);
            make.top.right.mas_equalTo(0);
        }];
        UITextField *textField = [[UITextField alloc] init];
        textField.placeholder = @"";
        textField.textColor = kColor666666;
        textField.font = [UIFont systemFontOfSize:14];
        textField.textAlignment = NSTextAlignmentRight;
        [fieldView addSubview:textField];
        [textField mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.contentView);
            make.right.equalTo(fieldView).offset(-14);
            make.left.height.equalTo(fieldView);
        }];
        self.fieldView = fieldView;
        
        //image
        UIView *headerView = [[UIView alloc] init];
        headerView.hidden = YES;
        [self.contentView addSubview:headerView];
        [headerView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(100);
            make.bottom.mas_equalTo(-1);
            make.top.right.mas_equalTo(0);
        }];
        UIImageView *header = [[UIImageView alloc] init];
        header.backgroundColor = [UIColor systemGray5Color];
        [headerView addSubview:header];
        [header mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(header.mas_height).multipliedBy(1);
            make.centerY.equalTo(self.contentView);
            make.right.equalTo(headerView).offset(-14);
            make.top.equalTo(self.contentView).offset(15);
        }];
        self.headerView = headerView;
        
    }
    return self;
}

- (void)setCellType:(PersonalCellType)cellType
{
    _cellType = cellType;
    self.arrowView.hidden = cellType != PersonalCellType_Arrow;
    self.fieldView.hidden = cellType != PersonalCellType_Field;
    self.headerView.hidden = cellType != PersonalCellType_Image;
}

- (void)setMainStr:(NSString *)mainStr
{
    self.mainLabel.text = mainStr;
}


@end
